package com.tuotu.gps.view;

import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.view.View;
import android.widget.RelativeLayout;

import com.tuotu.gps.LogoActivity;
import com.tuotu.gps.R;
import com.tuotu.gps.RecordActivity2;
import com.tuotu.gps.UploadActivity2;
import com.tuotu.gps.utils.Preference;

/**
 * Created by XuYeWen on 2018/3/13.
 */

public class MenuDialog extends Dialog{

    private onMenuActionListener mMenuActionListener;
    private Context mContext;
    private View mLayoutMenueAll;
    private View mLayoutDeleteAll;
    private View mLayoutUserHelp;

    public MenuDialog(@NonNull Context context) {
        super(context, R.style.SelfDialog);
        this.mContext=context;
    }

    public void setmMenuActionListener(onMenuActionListener mMenuActionListener) {
        this.mMenuActionListener = mMenuActionListener;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.layout_menu_dialog);
        getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
        getWindow().setLayout(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT);
        //按空白处不能取消动画
//        setCanceledOnTouchOutside(false);
        //点击鼠标返回键不取消动画
//        setCancelable(false);
        initView();
    }

    private void initView() {
        mLayoutMenueAll=findViewById(R.id.layout_menu_all);
        mLayoutDeleteAll=findViewById(R.id.layout_delete_all);
        mLayoutUserHelp=findViewById(R.id.layout_user_help);
        mLayoutMenueAll.setVisibility(View.VISIBLE);
        mLayoutDeleteAll.setVisibility(View.GONE);
        mLayoutUserHelp.setVisibility(View.GONE);
        findViewById(R.id.menu_upload_data).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
               if(null!=mMenuActionListener)
                   mMenuActionListener.menuUploadData();
               cancel();
            }
        });

        findViewById(R.id.menu_check_data).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if(null!=mMenuActionListener)
                    mMenuActionListener.menuCheckData();
                cancel();
            }
        });

        findViewById(R.id.menu_delete_data_noupload).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                mLayoutMenueAll.setVisibility(View.GONE);
                mLayoutDeleteAll.setVisibility(View.VISIBLE);
            }
        });

        findViewById(R.id.menu_user_logout).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                cancel();
                if(null!=mMenuActionListener) {
                    mMenuActionListener.menuUserLogout();
                }
            }
        });

        findViewById(R.id.menu_cancle).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                cancel();
            }
        });

        findViewById(R.id.menu_deleteAll_yes).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if(null!=mMenuActionListener)
                    mMenuActionListener.menuDeleteNoUploadData();
                cancel();
            }
        });

        findViewById(R.id.menu_deleteAll_no).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mLayoutMenueAll.setVisibility(View.VISIBLE);
                mLayoutDeleteAll.setVisibility(View.GONE);
            }
        });

        findViewById(R.id.menu_user_help).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mLayoutMenueAll.setVisibility(View.GONE);
                mLayoutUserHelp.setVisibility(View.VISIBLE);
            }
        });
    }

    @Override
    public void onBackPressed() {
        if(mLayoutUserHelp.getVisibility()==View.VISIBLE){
            mLayoutMenueAll.setVisibility(View.VISIBLE);
            mLayoutUserHelp.setVisibility(View.GONE);
        }else {
            super.onBackPressed();
        }
    }

    public interface onMenuActionListener{
        void menuUploadData();
        void menuCheckData();
        void menuDeleteNoUploadData();
        void menuUserLogout();
    }

}
